package com.hackordie.interfaces;

import com.hackordie.commons.authorities.Role;
import com.hackordie.commons.authorities.User;
import com.hackordie.commons.authorities.UserAccess;
import com.hackordie.exceptions.HackOrDieException;
import com.hackordie.operations.AHackOrDieOperation;
import com.hackordie.operations.creates.CreateUser;
import com.hackordie.operations.deletes.DeleteUser;
import com.hackordie.operations.queries.QueryCountUsers;
import com.hackordie.operations.queries.QueryLoginUser;
import com.hackordie.operations.queries.QueryUsers;
import com.hackordie.operations.updates.UpdateUser;

public class HackOrDieManager implements IHackOrDieManager {

	private AHackOrDieOperation operation;

	public HackOrDieManager() {
		super();
	}

	@Override
	public boolean loginUser(String username, String password) throws HackOrDieException {
		operation = new QueryLoginUser(username, password);
		operation.execute();
		return true;
	}

	@Override
	public boolean createUser(User user) throws HackOrDieException {
		operation = new CreateUser(user);
		operation.execute();
		return true;
	}

	@Override
	public boolean deleteUser(int id) throws HackOrDieException {
		operation = new DeleteUser(id);
		operation.execute();
		return true;
	}

	@Override
	public boolean deleteUser(String username) throws HackOrDieException {
		operation = new DeleteUser(username);
		operation.execute();
		return true;
	}

	@Override
	public boolean updateUser(User user) throws HackOrDieException {
		operation = new UpdateUser(user);
		operation.execute();
		return true;
	}

	@Override
	public boolean enableUser(int id) throws HackOrDieException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean enableUser(String username) throws HackOrDieException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean disableUser(int id) throws HackOrDieException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean disableUser(String username) throws HackOrDieException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean setRoleUser(int id, Role[] roles) throws HackOrDieException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean setRoleUser(String username, Role[] roles) throws HackOrDieException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public User getUser(int id) throws HackOrDieException {
		operation = new QueryUsers(id);
		return (User) operation.execute().getObject();
	}

	@Override
	public User getUser(String username) throws HackOrDieException {
		operation = new QueryUsers(username);
		return (User) operation.execute().getObject();
	}

	@Override
	public User[] getAllUsers() throws HackOrDieException {
		operation = new QueryUsers();
		return (User[]) operation.execute().getObject();
	}

	@Override
	public User[] getAllUsersByRange(int first, int last) throws HackOrDieException {
		operation = new QueryUsers(first, last);
		return (User[]) operation.execute().getObject();
	}

	@Override
	public int countAllUsers() throws HackOrDieException {
		operation = new QueryCountUsers();
		return (Integer) operation.execute().getObject();
	}

	@Override
	public UserAccess[] getUserAccess(int id) throws HackOrDieException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public UserAccess[] getUserAccess(String username) throws HackOrDieException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public UserAccess[] getAllAccess() throws HackOrDieException {
		// TODO Auto-generated method stub
		return null;
	}

}
